<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<script>
    /*
        1.话不多说,先看例子
     */
    function sum(x) {
        return x + 1;
    }

    function sumMore(x) {
        return Promise.resolve(x)
            .then(sum)
            .then(sum)
            .then(sum)
    }

    // 我艹,还能这样玩
    sumMore(0).then(console.log);

    // 还有一种更牛逼的
    function sumFarMore(x) {
        return [sum, sum, sum].reduce((pre, cur) => pre.then(cur), Promise.resolve(x))
    }

    sumFarMore(0).then(console.log)

    // 进一步封装
    function compose(...fns) {
        return (x) => fns.reduce((promise, fn) => promise.then(fn), Promise.resolve(x))
    }

    compose(sum, sum, sum)(0).then(console.log)
    
</script>
</body>
</html>